using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using THSLib;using THSERP.BaseProvider;

namespace THSERP.Modules.Report
{
    public partial class RP020 : ReportForm
    {
        private ChartControl EmployeeComparisonChart;
        public enum FilterType { ExtPrice = 1, ExtCost = 2, Qty = 3 };
        public FilterType filterType;
        public RP020()
        {
            InitializeComponent();
            EmployeeComparisonChart = fld_chcEmployeeComparison;
            filterType = FilterType.ExtPrice;
            fld_lblFilterType.Text = fld_ctxItemPrice.Text;
        }

        private void ViewEmployeeComparisonChart()
        {
            DateTime from = Convert.ToDateTime(fld_dteSearchFromARInvoiceDate.EditValue);
            DateTime to = Convert.ToDateTime(fld_dteSearchToARInvoiceDate.EditValue);
            String searchQuery = ((Modules.Report.ReportModule)this.Module).GenerateInvoiceItemSearchQuery(from,to, 0, 0, 0, 0, "i.FK_HREmployeeID");

            ARInvoiceItemsController objInvoiceItemsController = new ARInvoiceItemsController();
            DataSet ds = objInvoiceItemsController.GetDataSet(searchQuery);
            List<double> lstTypeValue = new List<double>();
            EmployeeComparisonChart.Series[0].Points.Clear();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                ARInvoiceItemsInfo objInvoiceItemsInfo = (ARInvoiceItemsInfo)objInvoiceItemsController.GetObjectFromDataRow(row);
                HREmployeesInfo objEmployeesInfo = (HREmployeesInfo)new HREmployeesController().GetObjectByID((int)row["FK_HREmployeeID"]);
                SeriesPoint point = new SeriesPoint();
                switch (filterType)
                {
                    case FilterType.ExtPrice:
                        point = new SeriesPoint(objEmployeesInfo.HREmployeeLName, objInvoiceItemsInfo.ARInvoiceItemNetAmount);
                        break;
                    case FilterType.ExtCost:
                        point = new SeriesPoint(objEmployeesInfo.HREmployeeLName, objInvoiceItemsInfo.ARInvoiceItemTotalCost);
                        break;
                    case FilterType.Qty:
                        point = new SeriesPoint(objEmployeesInfo.HREmployeeLName, objInvoiceItemsInfo.ARInvoiceItemProductQty);
                        break;
                }
                EmployeeComparisonChart.Series[0].Points.Add(point);
            }
        }

        private void fld_ctxItemPrice_Click(object sender, EventArgs e)
        {
            fld_lblFilterType.Text = fld_ctxItemPrice.Text;
            filterType = FilterType.ExtPrice;
            ViewEmployeeComparisonChart();
        }

        private void fld_ctxItemCost_Click(object sender, EventArgs e)
        {
            fld_lblFilterType.Text = fld_ctxItemCost.Text;
            filterType = FilterType.ExtCost;
            ViewEmployeeComparisonChart();
        }

        private void fld_ctxItemQty_Click(object sender, EventArgs e)
        {
            fld_lblFilterType.Text = fld_ctxItemQty.Text;
            filterType = FilterType.Qty;
            ViewEmployeeComparisonChart();
        }

        private void RP020_Load(object sender, EventArgs e)
        {
            ViewEmployeeComparisonChart();
        }

        private void fld_btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void fld_btnApply_Click(object sender, EventArgs e)
        {
            ViewEmployeeComparisonChart();
        }
    }
}